#pragma once

#include <Arduino.h>
#include <FS.h>

namespace ganix
{
    namespace fs
    {

        void init() {
            SPIFFS.begin();
        }

        String load(String path) {
            File f = SPIFFS.open(path, "r");
            Serial.printf("loaded file size: %d\n", f.size());
            String ret = "";
            String buf = f.readString();
            f.close();
            return buf;
        }

        void save(String path, String data, bool append = false) {
            File f = SPIFFS.open(path, append ? "a" : "w");
            f.println(data);
            f.println('\0');
            f.close();
        }
    } // namespace fs
} // namespace ganix
